/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 * Licensed under the Apache License, Version 2.0(the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef VETH_H
#define VETH_H

#include "eth_general_types.h"
#include "sim_port_adapt.h"

typedef enum {
    ETH_DISABLE = 0,
    ETH_ENABLE
} veth_option_type;

typedef struct {
    uint16 eth_ctrl_rx_buf_len_byte;
    uint16 eth_ctrl_tx_buf_len_byte;
    veth_option_type tx_int_enable;
    veth_option_type rx_int_enable;
    uint8 eth_rx_buf_total;
    uint8 eth_tx_buf_total;
    uint8 eth_mac_address[6];
    uint8 eth_ctrl_idx;
    int dev_fd; /* tap device file descriptor */
} veth_core_ctrl_config_type; /* Single controller configuration */

typedef struct {
    veth_core_ctrl_config_type *veth_core_ctrl_ptr;
    uint8 veth_max_controllers;
} veth_core_config_type; /* Configuration of all controllers on a core */

typedef struct {
    veth_core_config_type *veth_core_add[OS_CORE_CNT];
    uint8 *veth_node_idxmap_ptr;
} veth_config_type;

BufReq_ReturnType veth_provide_tx_buffer(const uint8 ctrl_idx, eth_buf_idx_type *const bufidx_ptr, uint8 **const buf_ptr,
                    uint16 *const lenbyte_ptr);
Std_ReturnType veth_transmit(const uint8 ctrl_idx, const eth_buf_idx_type buf_idx, const eth_frame_type frame_type,
                const boolean tx_confirmation, const uint16 len_byte, const uint8 *const phys_addr_ptr);
void veth_init(const veth_config_type *veth_config_ptr);
void veth_tx_ctrl0_irq_hdlr(void);
void veth_rx_ctrl0_irq_hdlr(void);
void veth_tx_confirmation(uint8 ctrl_idx);
void veth_receive(uint8 ctrl_idx);
void veth_tx_done_fun(const uint8 ctrl_idx);
void veth_rx_done_fun(const uint8 ctrl_idx);
Std_ReturnType veth_get_controller_mode(const uint8 ctrl_idx, eth_mode_type *const ctrl_mode_ptr);
Std_ReturnType veth_get_phys_addr(const uint8 ctrl_idx, uint8 *const phys_addr_ptr);
Std_ReturnType veth_set_controller_mode(const uint8 ctrl_idx, const eth_mode_type ctrl_mode);
Std_ReturnType veth_set_phys_addr(const uint8 ctrl_idx, const uint8 *const phys_addr_ptr);

#endif
